/**  
 * @Title:  OrderServiceSaticProxy.java   
 * @Package Order   
 * @Description:    TODO   
 * @author: hezhiqin     
 * @date:   2019年4月1日 下午4:08:24   
 */  
package Order;

import java.text.SimpleDateFormat;
import java.util.Date;

/**   
 * @ClassName:  OrderServiceSaticProxy   
 * @Description:TODO(切换数据源的代理)   
 * @author: hezhiqin
 * @date:   2019年4月1日 下午4:08:24   
 *      
 */
public class OrderServiceSaticProxy implements IOrderService{
	
	private SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
	
	private IOrderService orderService;

	/**   
	 * @Title:  OrderServiceSaticProxy   
	 * @Description:    TODO(模拟speing注入)   
	 * @param:  @param orderService 
	 * @author: hezhiqin
	 * @throws   
	 */
	public OrderServiceSaticProxy(IOrderService orderService) {
		
		this.orderService = orderService;
	}

	/**    
	 * @param order
	 * @return   
	 * @see Order.IOrderService#createOrder(Order.Order)   
	 */
	@Override
	public int createOrder(Order order) {
		before();
		Long time = order.getCreateTime();
		Integer dbRouter = Integer.valueOf(yearFormat.format(new Date(time)));
		System.out.println("静态代理类自动分配到【DB_" + dbRouter + "】数据源处理数据。");
		DynamicDataSourceEntry.set(dbRouter);
		orderService.createOrder(order);
		after();
		return 0;
	}
	
	private void before(){
		System.out.println("Proxy before method.");
	}
	
	
	private void after(){
		System.out.println("Proxy after method.");
	}
	

}
